<?php


namespace App\Logic;


use App\Models\User;
use App\server\JwtServer;
use App\server\SMS\CodeServer;

class LoginLogic
{


    /**
     * 用户登录注册
     */
    public static function adminLogin($key){

        $res=CodeServer::verifyCode($key);
        if($res!=true)throw new \Exception('验证失败');
        $user=User::where('phone',$key['phone'])->first();
        if(empty($user)){
            $user_id=User::create(['phone'=>$key['phone']]);
            $token=JwtServer::jwtEncode($user_id);
        }else{
            $token=JwtServer::jwtEncode($user['id']);
        }
        return $token;
    }
}
